/// 配置文件

use config as extConfig;
use serde::Deserialize;

#[derive(Deserialize)]
pub struct ServerConfig {
    pub host: String,
    pub port: i32,
}

#[derive(Deserialize)]
pub struct Config {
    pub server: ServerConfig,
    pub pg: deadpool_postgres::Config
}

impl Config {
    //从.env文件读取配置
    pub fn from_env() -> Result<Self, extConfig::ConfigError> {
        let mut cfg = extConfig::Config::new();
        cfg.merge(extConfig::Environment::new())?;
        cfg.try_into()
    }
}
